Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Avoid allocting in pre_exec closure#1

Merged
saltnpepper97 merged 1 commit intosaltnpepper97:mainfrom
sylfn:pre_exec
Dec 2, 2025
Merged

Avoid allocting in pre_exec closure#1
saltnpepper97 merged 1 commit intosaltnpepper97:mainfrom
sylfn:pre_exec

Conversation

@sylfn
Copy link
Copy Markdown
Contributor

@sylfn sylfn commented Nov 21, 2025

Error::new allocates memory (see rust-lang/rust#148971). This is bad in multi-threaded programs, which snug AFAIK is. If the fork occurs while the allocator lock is held by another thread, deadlocks can occur, since there's no one left in the new process to unlock the mutex. I do not believe this is UB, and modern libc offer protections against this issue, but this isn't POSIX-compliant and should preferably be avoided.

nix provides a non-allocating impl From<nix::Error> for std::io::Error, use it instead. This also ensures the correct error code is forwarded to the parent process, instead of the default -EINVAL.

@saltnpepper97 saltnpepper97 merged commit 91fa3b4 into saltnpepper97:main Dec 2, 2025
@saltnpepper97
Copy link
Copy Markdown
Owner

saltnpepper97 commented Dec 2, 2025

@yuki0iq

Thank you, you taught me something!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants